package com.gjy.redis.controller;

import com.gjy.redis.annotation.MethodExecutionTime;
import com.gjy.redis.domain.AjaxResult;
import org.redisson.Redisson;
import org.redisson.api.RBitSet;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-07-13 14:58:49
 */
@RestController
@RequestMapping("/bitmap")
public class BitmapController {

    @Resource
    private Redisson redisson1;

    @PostMapping("/set")
    @MethodExecutionTime
    public AjaxResult setBit(@RequestParam Long end) {
        RBitSet bit = redisson1.getBitSet("BS_1");
        for (long i = 0L; i < end; i++) {
            bit.setAsync(i);
        }
        return AjaxResult.builder().build();
    }

    @MethodExecutionTime
    @PostMapping("/count")
    public AjaxResult count() {
        RBitSet bit = redisson1.getBitSet("BS_1");
        long size = bit.size();
        return AjaxResult.builder().data(size).build();
    }
}
